//
//  SunThirdVC.m
//  Xspcf
//
//  Created by sunshine on 16/10/11.
//  Copyright © 2016年 小小算盘. All rights reserved.
//

#import "SunThirdVC.h"
#import "SunMyOrderVC.h"
#import "SunMyCardsVC.h"
#import "SunBankManagerVC.h"
#import "SunLoginVC.h"
#import "SunOptionVC.h"
#import "SunInputVC.h"
#import "SunGetMoneyVC.h"
#import "SunMyMsgVC.h"
#import "SunWebVC.h"
#import "SunDelegateWebVC.h"
/////////////////
#import "MyLuckyDrawController.h"
/////////////////
#import "OpenBindSuccessViewController.h"
#import "WXApi.h"



#undef Y
#define Y(y) BY(y)
@interface SunThirdVC ()
{
    UILabel *_userPhone;
    UILabel *_totalMoney;//总资产
    UILabel *_leaveMoney;//可用余额
    UILabel *_profitMoney;//累计收益
    Sun *_sun;
    UIView *_loginView;
    UIButton *_eye;
    BOOL _showBind;
}
@end

@implementation SunThirdVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BACKGROUND;
    [self initData];
    [self creatUI];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    if (![[NSUserDefaults standardUserDefaults] boolForKey:KLOGIN]) {
        [self showLogin];
    }else {
        if (_loginView) {
            [_sun hideAll];
        }
        [self requestToUser];
    }
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"third_hide"]) {
        _eye.selected = NO;
    }else {
        _eye.selected = YES;
    }
    [self showDetails:_eye];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)showLogin{
    if (!_loginView) {
        _loginView = [[UIView alloc]init];
        UIView *view = [[UIView alloc]init];
        [_loginView addSubview:view];
        UIImageView *imgV1 = [[UIImageView alloc]init];
        [view addSubview:imgV1];
        [imgV1 setFrame:CGRectMake(-3, SCREENHEIGHT - 280, SCREENWIDTH + 26, 250)];
        imgV1.image = [UIImage imageNamed:@"hb_BG"];
        imgV1.userInteractionEnabled = YES;
        UIButton *btn = [[UIButton alloc]init];
        [imgV1 addSubview:btn];
        [btn lt_XcenterTo:nil save:YES];
        [btn lt_setTop:90 to:nil save:YES];
        [btn lt_setSize:CGSizeMake(286, 44) save:YES];
        [btn setBackgroundImage:[UIImage imageNamed:@"sign_button"] forState:UIControlStateNormal];
        [btn setTitle:@"登录" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:18]];
        [btn addTarget:self action:@selector(gotoLogin) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *btn2 = [[UIButton alloc]init];
        [imgV1 addSubview:btn2];
        [btn2 lt_XcenterTo:nil save:YES];
        [btn2 lt_setTop:20 to:btn save:YES];
        [btn2 lt_setSize:CGSizeMake(286, 44) save:YES];
        [btn2 setBackgroundImage:[UIImage imageNamed:@"register_button"] forState:UIControlStateNormal];
        [btn2 setTitle:@"注册" forState:UIControlStateNormal];
        [btn2 setTitleColor:[UIColor colorWithHexString:@"F96D60"] forState:UIControlStateNormal];
        [btn2.titleLabel setFont:[UIFont systemFontOfSize:18]];
        [btn2 addTarget:self action:@selector(gotoLogin) forControlEvents:UIControlEventTouchUpInside];
        
        UILabel *label = [[UILabel alloc]init];
        [imgV1 addSubview:label];
        [label lt_layoutView:label side:SunCenterX to:nil toSide:SunCenterX withSize:1 offset:X(5) save:YES];
        [label lt_setTop:Y(10) to:btn2 save:YES];
        label.textColor = [UIColor colorWithHexString:@"000000"];
        label.font = [UIFont systemFontOfSize:13];
        label.text = [Sun getUser:SAFETEXT];
        UIImageView *imgV2 = [[UIImageView alloc]init];
        [imgV1 addSubview:imgV2];
        [imgV2 lt_YcenterTo:label save:YES];
        [imgV2 lt_setRight:X(3) to:label save:YES];
        imgV2.image = [UIImage imageNamed:@"safe_icon"];
        [view lt_topEqual:imgV1 save:YES];
        [view lt_bottomEqual:imgV1 save:YES];
        [view lt_leftEqual:imgV1 save:YES];
        [view lt_rightEqual:imgV1 save:YES];
        [view lt_XYcenterTo:nil save:YES];
    }
    [_sun show:_loginView to:self shouldReturn:NO];
    [_loginView lt_All:SunEdgesMake(0, 0, 0, 0) save:YES];
}

- (void)initData{
    _sun = [[Sun alloc]init];
}

- (void)creatUI{
    // 上方区域
    UIView *headView = [[UIView alloc]init];
    [self.view addSubview:headView];
    headView.backgroundColor = WHITE;
    [headView lt_Top:SunEdgesMake(0, 0, 0, 258) to:nil save:YES];
    // logo
    UIImageView *logoImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"third_head"]];
    [headView addSubview:logoImage];
    [logoImage lt_XYcenterTo:nil save:YES];
    [logoImage lt_setLeft:X(17) to:nil save:YES];
    [logoImage lt_setTop:35 to:nil save:YES];
    [logoImage lt_setSize:CGSizeMake(43, 43) save:YES];
    // ->名字
    _userPhone = [[UILabel alloc]init];
    [headView addSubview:_userPhone];
    [_userPhone lt_YcenterTo:logoImage save:YES];
    [_userPhone lt_setHeight:Y(12) save:YES];
    [_userPhone lt_setLeft:10 to:logoImage save:YES];
    _userPhone.textColor = [UIColor colorWithHexString:@"5F5F5F"];
    _userPhone.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    _userPhone.text = @"***********";
    // 设置按钮（安全中心）
    UIButton *setButton = [[UIButton alloc]init];
    [headView addSubview:setButton];
    [setButton setImage:[UIImage imageNamed:@"third_set"] forState:UIControlStateNormal];
    [setButton lt_setSize:CGSizeMake(30, 30) save:YES];
    [setButton lt_YcenterTo:logoImage save:YES];
    [setButton lt_setRight:X(7) to:nil save:YES];
    [setButton addTarget:self action:@selector(optionAction) forControlEvents:UIControlEventTouchUpInside];
    // 消息按钮
    UIButton *megButton = [[UIButton alloc]init];
    [headView addSubview:megButton];
    [megButton setImage:[UIImage imageNamed:@"third_message"] forState:UIControlStateNormal];
    [megButton lt_setSize:CGSizeMake(30, 30) save:YES];
    [megButton lt_YcenterTo:logoImage save:YES];
    [megButton lt_setRight:X(10) to:setButton save:YES];
    [megButton addTarget:self action:@selector(messageAction) forControlEvents:UIControlEventTouchUpInside];
    // 总资产文字
    UILabel *label1 = [[UILabel alloc]init];
    [headView addSubview:label1];
    [label1 lt_setTop:89 to:nil save:YES];
    [label1 lt_setLeft:X(152) to:nil save:YES];
    label1.textColor = COLOR_TITLE_MINOR;
    label1.font = FONT_TITLE_FOUR;
    label1.text = @"总资产(元)";
    // 隐藏/显示
    _eye = [[UIButton alloc]init];
    [headView addSubview:_eye];
    [_eye lt_setLeft:4 to:label1 save:YES];
    [_eye lt_YcenterTo:label1 save:YES];
    [_eye lt_setSize:CGSizeMake(40, 30) save:YES];
    [_eye setImage:[UIImage imageNamed:@"third_eye"] forState:UIControlStateNormal];
    [_eye setImage:[UIImage imageNamed:@"third_uneye"] forState:UIControlStateSelected];
    [_eye addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
    // 总资产数字
    _totalMoney = [[UILabel alloc]init];
    [headView addSubview:_totalMoney];
    [_totalMoney lt_XcenterTo:nil save:YES];
    [_totalMoney lt_setTop:13 to:label1 save:YES];
    [_totalMoney lt_setHeight:Y(36) save:YES];
    _totalMoney.textColor = COLOR_MAIN;
    _totalMoney.font = FONT_NUM_MID;
    _totalMoney.text = @"0.00";
    _totalMoney.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapToTotal)];
    [_totalMoney addGestureRecognizer:tap1];
    // 累计收益
    UIImageView *rightBg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"third_button"]];
    [headView addSubview:rightBg];
    [rightBg setFrame:CGRectMake(X(104), 165, SCREENWIDTH-X(104+93), 30)];
//    [rightBg lt_Bottom:SunEdgesMake(SCREENWIDTH / 2.0 + 1, 63, 0, 60) to:nil save:YES];
    UILabel *label3 = [[UILabel alloc]init];
    [rightBg addSubview:label3];
    [label3 lt_YcenterTo:nil save:YES];
    [label3 lt_setHeight:Y(14) save:YES];
    [label3 lt_setLeft:0 to:nil save:YES];
    label3.textColor = COLOR_TITLE_MAIN;
    label3.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    label3.text = @"累计收益(元)";
    _profitMoney = [[UILabel alloc]init];
    [rightBg addSubview:_profitMoney];
    [_profitMoney lt_YcenterTo:nil save:YES];
    [_profitMoney lt_setHeight:Y(20) save:YES];
    [_profitMoney lt_setLeft:X(20) to:label3 save:YES];
    _profitMoney.textColor = COLOR_TITLE_MAIN;
    _profitMoney.font =  [UIFont fontWithName:@"PingFangSC-Medium" size:16];
    _profitMoney.text = @"0.00";
    UIImageView *profitNext = [[UIImageView alloc]init];
    [rightBg addSubview:profitNext];
    [profitNext setImage:[UIImage imageNamed:@"first_next"]];
    [profitNext lt_YcenterTo:nil save:YES];
    [profitNext lt_setSize:CGSizeMake(5, 9) save:YES];
    [profitNext lt_setLeft:6 to:_profitMoney save:YES];
    rightBg.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapToProfit)];
    [rightBg addGestureRecognizer:tap3];
    
    UIImageView *headLine = [[UIImageView alloc]init];
    [headView addSubview:headLine];
    [headLine setImage:[UIImage imageNamed:@"all_line"]];
    [headLine setFrame:CGRectMake(15, 211, SCREENWIDTH-30, 2)];
    
    // 可用余额
    UIImageView *leftBg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"third_button"]];
    [headView addSubview:leftBg];
    [leftBg setFrame:CGRectMake(0, 213, SCREENWIDTH/2-1, 44)];
    UILabel *label2 = [[UILabel alloc]init];
    [leftBg addSubview:label2];
    [label2 lt_YcenterTo:nil save:YES];
    [label2 lt_setHeight:Y(14) save:YES];
    [label2 lt_setLeft:15 to:nil save:YES];
    label2.textColor = COLOR_TITLE_MAIN;
    label2.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    label2.text = @"账户余额";
    _leaveMoney = [[UILabel alloc]init];
    [leftBg addSubview:_leaveMoney];
    [_leaveMoney lt_YcenterTo:nil save:YES];
    [_leaveMoney lt_setHeight:Y(20) save:YES];
    [_leaveMoney lt_setRight:27 to:nil save:YES];
    _leaveMoney.textColor = COLOR_ALERT_DARK;
    _leaveMoney.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    _leaveMoney.text = @"0.00";
    UIImageView *leaveNext = [[UIImageView alloc]init];
    [leftBg addSubview:leaveNext];
    [leaveNext setImage:[UIImage imageNamed:@"first_next"]];
    [leaveNext lt_YcenterTo:nil save:YES];
    [leaveNext lt_setSize:CGSizeMake(5, 9) save:YES];
    [leaveNext lt_setRight:14 to:nil save:YES];
    leftBg.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapToLeave)];
    [leftBg addGestureRecognizer:tap2];
    
    UIImageView *lineY = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"second_line"]];
    [headView addSubview:lineY];
    [lineY lt_XcenterTo:nil save:YES];
    [lineY lt_setTop:2 to:headLine save:YES];
    [lineY lt_setSize:CGSizeMake(2, 39) save:YES];
    // 充值
    UIButton *inputButton = [[UIButton alloc]init];
    [headView addSubview:inputButton];
    [inputButton setBackgroundImage:[UIImage imageNamed:@"third_in_btn"] forState:UIControlStateNormal];
    [inputButton lt_setSize:CGSizeMake(X(79), X(29)) save:YES];
    [inputButton lt_setTop:12 to:headLine save:YES];
    [inputButton lt_setLeft:X(12) to:lineY save:YES];
    UILabel *inputBtnLabel = [[UILabel alloc]init];
    [inputButton addSubview:inputBtnLabel];
    inputBtnLabel.text = @"充值";
    inputBtnLabel.textColor = [UIColor colorWithHexString:@"FFFFFF"];
    inputBtnLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    [inputBtnLabel lt_XcenterTo:nil save:YES];
    [inputBtnLabel lt_setTop:0 to:nil save:YES];
    [inputButton addTarget:self action:@selector(inputAction) forControlEvents:UIControlEventTouchUpInside];
    // 提现
    UIButton *getMoneyButton = [[UIButton alloc]init];
    [headView addSubview:getMoneyButton];
    [getMoneyButton setBackgroundImage:[UIImage imageNamed:@"third_out_btn"] forState:UIControlStateNormal];
    [getMoneyButton lt_setSize:CGSizeMake(X(70), X(20)) save:YES];
    [getMoneyButton lt_setTop:12 to:headLine save:YES];
    [getMoneyButton lt_setRight:X(15) to:nil save:YES];
    [getMoneyButton setTitle:@"提现" forState:UIControlStateNormal];
    [getMoneyButton setTitleColor:[UIColor colorWithHexString:@"FA7060"] forState:UIControlStateNormal];
    getMoneyButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    [getMoneyButton addTarget:self action:@selector(getMoneyAction) forControlEvents:UIControlEventTouchUpInside];
    
#pragma mark- 下方区域
    UIView *bottom = [[UIView alloc]init];
    [self.view addSubview:bottom];
    bottom.backgroundColor = WHITE;
    [bottom lt_Top:SunEdgesMake(4, 0, 0, SCREENHEIGHT - headView.frame.size.height) to:headView save:YES];
    bottom.backgroundColor = WHITE;
    
    NSArray *bottomIcons = @[@"person_ic_wdtz",@"person_ic_wdkq",@"person_ic_aqzx",@"person_ic_yhkb",@"person_ic_yqhy",@"person_ic_fxcp",@"person_ic_gzwm",@"person_ic_gywm"];
    NSArray *bottomTitles = @[@"我的投资",@"我的卡券",@"安全中心",@"银行卡包",@"邀请有礼",@"风险测评",@"关注我们",@"关于我们"];
    for (int i = 0; i< bottomTitles.count; i++) {
        UIButton *bottomBtn = [[UIButton alloc]init];
        bottomBtn.tag = 100 + i;
        [bottomBtn addTarget:self action:@selector(bottomBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [bottom addSubview:bottomBtn];
        [bottomBtn setFrame:CGRectMake(i%2*SCREENWIDTH/2, i/2*45, SCREENWIDTH/2-2, 44)];
        UIImageView *imgView = [[UIImageView alloc]init];
        [bottomBtn addSubview:imgView];
        [imgView setImage:[UIImage imageNamed:bottomIcons[i]]];
        [imgView setFrame:CGRectMake(X(15), 12, 20, 20)];
        UILabel *titLabel = [[UILabel alloc]init];
        [bottomBtn addSubview:titLabel];
        titLabel.text = bottomTitles[i];
        [titLabel setFrame:CGRectMake(X(40), 12, 100, 20)];
        titLabel.textColor = COLOR_TITLE_MAIN;
        titLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
        UIImageView *bottomNext = [[UIImageView alloc]init];
        [bottomNext setImage:[UIImage imageNamed:@"first_next"]];
        [bottomBtn addSubview:bottomNext];
        [bottomNext lt_setSize:CGSizeMake(5, 9) save:YES];
        [bottomNext lt_setRight:X(7) to:nil save:YES];
        [bottomNext lt_YcenterTo:nil save:YES];
        UILabel *numLabel = [[UILabel alloc]init];
        [bottomBtn addSubview:numLabel];
        numLabel.tag = 200 + i;
        numLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
        numLabel.textColor = COLOR_TITLE_MINOR;
        numLabel.textAlignment = NSTextAlignmentRight;
        [numLabel lt_YcenterTo:nil save:YES];
        [numLabel lt_setRight:X(7) to:bottomNext save:YES];
        if (i%2 == 1) {
            UIImageView *bottomLine = [[UIImageView alloc]init];
            [bottom addSubview:bottomLine];
            [bottomLine setImage:[UIImage imageNamed:@"all_line"]];
            [bottomLine setFrame:CGRectMake(15, (i/2+1)*45, SCREENWIDTH-30, 2)];
            UIImageView *lineY = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"second_line"]];
            [bottom addSubview:lineY];
            [lineY lt_XcenterTo:nil save:YES];
            [lineY lt_setBottom:2 to:bottomLine save:YES];
            [lineY lt_setSize:CGSizeMake(2, 39) save:YES];
        }
    }
    
    UILabel *servicePhone = [[UILabel alloc]init];
    [bottom addSubview:servicePhone];
    servicePhone.text = KEFU;
    servicePhone.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
    servicePhone.textColor = COLOR_TITLE_MINOR;
    [servicePhone lt_XcenterTo:nil save:YES];
    [servicePhone lt_setTop:240 to:nil save:YES];
    
    UILabel *serviceTime = [[UILabel alloc]init];
    [bottom addSubview:serviceTime];
    serviceTime.text = @"工作日：09:00-18:00";
    serviceTime.font = [UIFont fontWithName:@"PingFangSC-Regular" size:10];
    serviceTime.textColor = COLOR_TITLE_MINOR;
    [serviceTime lt_XcenterTo:nil save:YES];
    [serviceTime lt_setTop:5 to:servicePhone save:YES];
    
}
#pragma mark- 界面跳转
- (void)bottomBtnAction:(UIButton*)btn {
//    NSArray *bottomTitles = @[@"我的投资",@"我的卡券",@"资金记录",@"银行卡包",@"邀请有礼",@"风险测评",@"关注我们",@"关于我们"];
    switch (btn.tag) {
        case 100:{
            SunMyOrderVC *vc = [[SunMyOrderVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            break;
        }
        case 101:{
            SunMyCardsVC *vc = [[SunMyCardsVC alloc]init];
            [self.navigationController pushViewController:vc animated:NO];
            break;
        }
        case 102:
            [self optionAction];
            break;
        case 103:{
            NSDictionary *dic = [Sun getUser:USER];
            if ([[dic objectForKey:@"isActivate"] intValue] == 1) {
                [SunSupport shouldAlert:self code:UserActivate];
            }else if ([[dic objectForKey:@"status"] intValue] == 3) {
                SunBankManagerVC *vc = [[SunBankManagerVC alloc]init];
                [self.navigationController pushViewController:vc animated:YES];
            }else {
                [SunSupport shouldAlert:self code:UserOpen];
            }
            break;
        }
        case 104:{
            SunWebVC *vc = [[SunWebVC alloc]init];
            NSString *str = @"CZfSDQzsuDayjfzE";
            NSString *str1 =@"12345678";
            NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
            NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
            vc.urlStr = [NSString stringWithFormat:@"%@/topic/april_share?source=ios&token_id=%@&sign=%@",KWAP,token_id,md5Str];
            vc.titleName = @"邀请有礼";
            vc.share = YES;
            [self.navigationController pushViewController:vc animated:YES];
            break;
        }
        case 105:{
            SunWebVC *vc = [[SunWebVC alloc]init];
            NSString *str = @"CZfSDQzsuDayjfzE";
            NSString *str1 =@"12345678";
            NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
            NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
            vc.urlStr = [NSString stringWithFormat:@"%@/account/risk_evaluation?source=ios&token_id=%@&sign=%@",KWAP,token_id,md5Str];
            vc.titleName = @"风险测评";
            [self.navigationController pushViewController:vc animated:YES];
            break;
        }
        case 106:{
            [[Sun shareSun]alertAlign:NSTextAlignmentCenter title:@"温馨提示" content:@"您可在微信-通讯录-添加朋友-查找公众号搜索“小算盘”点击关注，可更方便地获取我们最新消息！\n（点击“去关注”即可复制账号，在微信中直接粘贴搜索哦）" left:@"去关注" right:@"取消" cancel:^{
                [[Sun shareSun]hideShow];
                UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
                pasteboard.string = @"xspcfw";
                [WXApi openWXApp];
            } sure:^{
                [[Sun shareSun]hideShow];
            } To:self];
            break;
        }
        case 107:{
            SunWebVC *vc = [[SunWebVC alloc]init];
            vc.urlStr = [NSString stringWithFormat:@"%@/More/getArticleByNid?nid=about&type=2&source=ios",KWAP];
            vc.titleName = @"公司简介";
            [self.navigationController pushViewController:vc animated:YES];
            break;
        }
        default:
            break;
    }
}
#pragma mark- 设置、消息
- (void)optionAction{
    SunOptionVC *vc = [[SunOptionVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)messageAction{
    SunMyMsgVC *vc = [[SunMyMsgVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark- 充值
- (void)inputAction {
    NSDictionary *dic = [Sun getUser:USER];
    if ([[dic objectForKey:@"isActivate"] intValue] == 1) {
        [SunSupport shouldAlert:self code:UserActivate];
    }else if ([[dic objectForKey:@"status"] intValue] == 3) {
        SunInputVC *vc = [[SunInputVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        [SunSupport shouldAlert:self code:UserOpen];
    }
}
#pragma mark- 提现
- (void)getMoneyAction {
    NSDictionary *dic = [Sun getUser:USER];
    if ([[dic objectForKey:@"isActivate"] intValue] == 1) {
        [SunSupport shouldAlert:self code:UserActivate];
    }else
        if ([[dic objectForKey:@"status"] intValue] == 3) {
            SunGetMoneyVC *vc = [[SunGetMoneyVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }else {
            [SunSupport shouldAlert:self code:UserOpen];
        }
}



- (NSString *)get:(NSString *)key from:(NSDictionary *)dic{
    if ([[dic objectForKey:key]isKindOfClass:[NSNumber class]]) {
        return [NSString stringWithFormat:@"%@",[dic objectForKey:key]];
    }else {
        return [dic objectForKey:key];
    }
}

- (void)updateViews{
    NSDictionary *dic = [Sun getUser:USER];
    _totalMoney.text = [NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"totalMoney"] doubleValue]];
    _leaveMoney.text = [NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"balanceMoney"] doubleValue]];
    _profitMoney.text = [NSString stringWithFormat:@"%.2f",[[dic objectForKey:@"totalProfit"] doubleValue]];

//    _userPhone.text = [Sun hidePhone:[dic objectForKey:@"phone"]];
    _userPhone.text = [dic objectForKey:@"name"];
    UILabel *tendLabel = [self.view viewWithTag:200];
    tendLabel.text = [NSString stringWithFormat:@"%@笔在投",[dic objectForKey:@"tenderingCount"]];
    UILabel *cardLabel = [self.view viewWithTag:201];
    cardLabel.text = [NSString stringWithFormat:@"%@张可用",[dic objectForKey:@"cardsCount"]];
    UILabel *typeLabel = [self.view viewWithTag:205];
    typeLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"risk"]];
}

- (void)tapToTotal{
    NSDictionary *dic = [Sun getUser:USER];
    if ([[dic objectForKey:@"isActivate"] intValue] == 1) {
        [SunSupport shouldAlert:self code:UserActivate];
    }else if ([[dic objectForKey:@"status"] intValue] == 3) {
        SunWebVC *vc = [[SunWebVC alloc]init];
        NSString *str = @"CZfSDQzsuDayjfzE";
        NSString *str1 =@"12345678";
        NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
        NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
        vc.urlStr = [NSString stringWithFormat:@"%@/account/total?source=ios&token_id=%@&sign=%@",KWAP,token_id,md5Str];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        [SunSupport shouldAlert:self code:UserOpen];
    }
    
    
}
- (void)tapToLeave{
    NSDictionary *dic = [Sun getUser:USER];
    if ([[dic objectForKey:@"isActivate"] intValue] == 1) {
        [SunSupport shouldAlert:self code:UserActivate];
    }else if ([[dic objectForKey:@"status"] intValue] == 3) {
        SunWebVC *vc = [[SunWebVC alloc]init];
        vc.title = @"可用余额";
        NSString *str = @"CZfSDQzsuDayjfzE";
        NSString *str1 =@"12345678";
        NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
        NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
        vc.urlStr = [NSString stringWithFormat:@"%@/account/use_money?source=ios&token_id=%@&sign=%@&jump=mj",KWAP,token_id,md5Str];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        [SunSupport shouldAlert:self code:UserOpen];
    }
    
}

- (void)tapToProfit{
    NSDictionary *dic = [Sun getUser:USER];
    if ([[dic objectForKey:@"isActivate"] intValue] == 1) {
        [SunSupport shouldAlert:self code:UserActivate];
    }else if ([[dic objectForKey:@"status"] intValue] == 3) {
        SunWebVC *vc = [[SunWebVC alloc]init];
        NSString *str = @"CZfSDQzsuDayjfzE";
        NSString *str1 =@"12345678";
        NSString *token_id=[Utility encryptStr:[NSString stringWithFormat:@"%@",[Sun getUser:ACCESSID]]  Key:str1 IV:nil];
        NSString *md5Str=[Utility md5:[NSString stringWithFormat:@"source=ios&token_id=%@&%@",token_id,str]];
        vc.urlStr = [NSString stringWithFormat:@"%@/account/total_interest?source=ios&token_id=%@&sign=%@",KWAP,token_id,md5Str];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        [SunSupport shouldAlert:self code:UserOpen];
    }
    
}

- (void)gotoLogin{
    SunLoginVC *vc = [[SunLoginVC alloc]init];
    vc.isWeb = NO;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)showDetails:(UIButton *)btn{
    if (btn.isSelected) {
        btn.selected = NO;
        [self updateViews];
        [Sun setUser:@"0" forKey:@"third_hide"];
    }else {
        btn.selected = YES;
        _totalMoney.text = @"***";
        _leaveMoney.text = @"***";
        _profitMoney.text = @"***";
        _userPhone.text = @"***";
        [Sun setUser:@"1" forKey:@"third_hide"];
    }
}
#pragma mark request
- (void)requestToUser{
    NSString *url = [NSString stringWithFormat:@"%@%@",KURL,API_USERINFO];
    [HttpRequest postURL:url withParam:nil success:^(id requestDic, NSString *msg) {
        [[Sun shareSun]hideActivity];
        if ([[Sun getUser:@"third_hide"] intValue] == 1) {
            _eye.selected = NO;
        }else {
            _eye.selected = YES;
        }
        [Sun setUser:requestDic forKey:USER];
        if ([[requestDic objectForKey:@"isActivate"] intValue] == 1) {
            [SunSupport shouldAlert:self code:UserActivate];
        }else if (!_showBind && [[requestDic objectForKey:@"status"] intValue] != 3) {
            _showBind = YES;
            [SunSupport shouldAlert:self code:UserOpen];
        }

        [self showDetails:_eye];
    } failure:^(NSString *errorInfo, int code) {
        [[Sun shareSun]showMsg:errorInfo];
        [[Sun shareSun]hideActivity];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
